package band.wukong.practice.springboot.boot.web.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 局部异常controller
 *
 * @author wukong(wukonggg@139.com)
 */
@RestController
@RequestMapping("/web/exception")
public class LocalExceptionController {

    @RequestMapping("/local")
    @ResponseBody
    String index() {
        int i = 1 / 0;
        return null;
    }

    @ExceptionHandler(Exception.class)
    public String handleException(Exception e) {
        if (e instanceof ArithmeticException) {
            return "局部-算数异常";
        } else {
            return "局部-非算数异常";
        }
    }

}
